//    Copyright (C) Kherty.  All rights reserved.
using System;
using OpenLS.Core.Serialization;

namespace OpenLS.Drawing.Diagram
{
    class Connection : IOfficeXmlSerializable
    {
        private string modelId; 
        private CxnType type;
        private string srcId;
        private string destId;
        private int srcOrd;
        private int destOrd;
        private string parTransId;
        private string sibTransId;
        private string presId;
        internal const string xmlName = "cxn";
        public void ReadXml(ReadContext context)
        {
            using (var c = context.Read(xmlName))
            {
                modelId = c.GetString("modelId");
                type = c.GetOptionalEnum("type", CxnType.ParendOf);
                srcId = c.GetString("srcId");
                destId = c.GetString("destId");
                srcOrd = c.GetUIntegerAsInteger("srcOrd");
                destOrd = c.GetUIntegerAsInteger("destOrd");
                parTransId = c.GetOptionalString("parTransId", "0");
                sibTransId = c.GetOptionalString("sibTransId", "0");
                presId = c.GetOptionalString("presId", "");
            }
        }
        public void WriteXml(WriteContext context)
        {
            using (var c = context.Write(xmlName))
            {
                c.SetString("modelId", modelId);
                c.SetOptionalEnum("type", type, CxnType.ParendOf);
                c.SetString("srcId", srcId);
                c.SetString("destId", destId);
                c.SetUIntegerAsInteger("srcOrd", srcOrd);
                c.SetUIntegerAsInteger("destOrd", destOrd);
                c.SetOptionalString("parTransId", parTransId, "0");
                c.SetOptionalString("sibTransId", sibTransId, "0");
                c.SetOptionalString("presId", presId, "");
            }
        }
    }
}